﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.ClickCricket.bll;

public partial class Series : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string path = Server.MapPath("Home.aspx");
        try
        {
            int seriesID = Convert.ToInt16(Request.Params.Get(0));
            com.ClickCricket.bll.Series s = SeriesService.Instance.getSeries(seriesID);
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Series Name::"));
            Label lbl = new Label();
            lbl.Text = s.SeriesName;
            Master.FindControl("ContentPlaceHolder1").Controls.Add(lbl);
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Countries Playing::"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
            LinkButton lnkBtn = new LinkButton();
            lnkBtn.Text = CountryService.Instance.getCountry(s.Country1ID).CountryName;
            lnkBtn.PostBackUrl = "~/Country.aspx?CountryID="+s.Country1ID;
            Master.FindControl("ContentPlaceHolder1").Controls.Add(lnkBtn);
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
            lnkBtn = new LinkButton(); 
            lnkBtn.Text = CountryService.Instance.getCountry(s.Country2ID).CountryName;
            lnkBtn.PostBackUrl = "~/Country.aspx?CountryID=" + s.Country2ID;
            Master.FindControl("ContentPlaceHolder1").Controls.Add(lnkBtn);
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));

            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));            
        

            List<Match> _matchList = MatchService.Instance.GetMatches(seriesID);
            for (int i = 0; i < _matchList.Count; i++)
            {
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Match::"+(i+1)));
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));            
                Match m = _matchList[i];
                Label mlbl = new Label();
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Venue::"));            
                mlbl.Text = m.Venue;
                Master.FindControl("ContentPlaceHolder1").Controls.Add(mlbl);
                mlbl = new Label();
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Date::"));
                mlbl.Text = m.Date.Date.ToShortDateString();
                Master.FindControl("ContentPlaceHolder1").Controls.Add(mlbl);
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Winner::"));
                mlbl = new Label();
                if (m.WinnerID != 0)
                {
                    mlbl.Text = CountryService.Instance.getCountry(m.WinnerID).CountryName;
                    Master.FindControl("ContentPlaceHolder1").Controls.Add(mlbl);
                }
                else
                {
                    Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("Yet to be played"));
                }

                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
            }
        }
        catch
        {
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<u>On Going Series</u>"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));

            List<com.ClickCricket.bll.Series> _seriesList = SeriesService.Instance.getOnGoingSeries();

            for (int i = 0; i < _seriesList.Count; i++)
            {
                LinkButton l = new LinkButton();
                l.Text = _seriesList[i].SeriesName;
                l.PostBackUrl = "~/Series.aspx?SeriesID=" + _seriesList[i].SeriesID;
                Master.FindControl("ContentPlaceHolder1").Controls.Add(l);
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));
            }
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<u>Up Coming Series</u>"));
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));
            _seriesList = SeriesService.Instance.getUpComingSeries();

            for (int i = 0; i < _seriesList.Count; i++)
            {
                LinkButton l = new LinkButton();
                l.Text = _seriesList[i].SeriesName;
                l.PostBackUrl = "~/Series.aspx?SeriesID=" + _seriesList[i].SeriesID;
                Master.FindControl("ContentPlaceHolder1").Controls.Add(l);
                Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br />"));
            }
        }

    }
}
